

import { autorun, makeAutoObservable } from "mobx";
import userStore from "src/pages/User/userStore";
import { MaskData } from "types/type";
import cancelSVG from "./img/cancel.svg";
import maskModelApi from "./MaskModelApi";

class MaskModelStore {
    constructor() {
        makeAutoObservable(this, {}, { deep: false });
    }

    show: boolean = false;
    setShow(show: boolean) {
        this.show = show;
    }

    pageNum: number = 1;
    pageSize: number = 12;
    hasMore: boolean = true;
    loading: boolean = false;
    total: number = 0;

    list: Array<MaskData> = [];//遮罩数据列表
    //获取数据
    getNextPage(reset: boolean = false) {
        if (reset) {
            this.pageNum = 1;
            this.hasMore = true;
        } else if (!this.hasMore || this.loading) {
            return;
        } else {
            this.pageNum++;
        }
        this.loading = true;
        maskModelApi.getListSvg(this.pageNum, this.pageSize).then(async (res) => {
            if (reset) {
                this.list = [];
                await new Promise(resolve => requestAnimationFrame(resolve));
                await new Promise(resolve => requestAnimationFrame(resolve));
                await new Promise(resolve => requestAnimationFrame(resolve));
                this.list = [
                    {
                        createBy: "admin",
                        createTime: "2025-08-19T10:48:07.000+08:00",
                        ifDel: false,
                        params: {},
                        searchValue: null,
                        status: null,
                        svgData: {},
                        svgFileUrl: "",
                        svgId: 0,
                        svgImageUrl: cancelSVG,
                        svgName: "qpdW2HeVW",
                        svgSort: 1,
                        svgType: "",
                        updateBy: "admin",
                        updateTime: "2025-08-19T10:48:07.000+08:00",
                    },
                    ...res.rows];
            } else {
                this.list = [...this.list, ...res.rows];
            }
            this.total = res.total;
            this.hasMore = (res.rows.length === this.pageSize);
            this.loading = false;
        });

    }

}

const maskModelStore = new MaskModelStore();

export default maskModelStore;